package org.home.learning;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import org.home.JDBC.Querys;

import javax.swing.*;


public class LocalizaCarro extends JFrame implements ActionListener {
	
	//criando e instanciando obj
		JLabel lb1 = new JLabel("Cadastro de Veiculos");
		JLabel lb2 = new JLabel("Modelo:");
		JLabel lb3 = new JLabel("Ano:");
		public static JLabel lb4 = new JLabel();
		JTextArea ta1 = new JTextArea();
				
		JButton bt1 = new JButton("Procurar");
		JButton bt2 = new JButton("Voltar");
		
		JTextField tx1 = new JTextField(15);
		JTextField tx2 = new JTextField(4);
		
		JPanel p1 = new JPanel();
		JPanel p2 = new JPanel();
		JPanel p3 = new JPanel();
		JPanel p4 = new JPanel();
		JPanel p5 = new JPanel();
		JPanel p6 = new JPanel();
		
		//construtor
			public LocalizaCarro() {
				
				add(p1);
				p1.setLayout(new GridLayout(5,1));
				setLocationRelativeTo(null);
				setSize(250,300);
				setTitle("Cadastro");
				
				//definindo layouts
				p2.setLayout(new FlowLayout(FlowLayout.CENTER));	
				p3.setLayout(new FlowLayout(FlowLayout.CENTER));		
				p4.setLayout(new FlowLayout(FlowLayout.CENTER));		
				p5.setLayout(new FlowLayout(FlowLayout.CENTER));
				p6.setLayout(new FlowLayout(FlowLayout.CENTER));
				
				//adicionando components ao panel	
				p4.add(lb1);	
				
				p2.add(lb2);
				p2.add(tx1);
				
				p2.add(lb3);
				p2.add(tx2);
				
				p5.add(ta1);
				
				p6.add(lb4);
				
				p3.add(bt1);
				bt1.addActionListener(this);
				
				p3.add(bt2);
				bt2.addActionListener(this);
				
				p1.add(p4);
				p1.add(p2);
				p1.add(p5);
				p1.add(p6);
				p1.add(p3);					
				
	}

	public void actionPerformed(ActionEvent e) {
		
			if (e.getSource() == bt1) {
			
			try {
			Querys.queryProcurar(tx1.getText(), Integer.parseInt(tx2.getText()));
			
			lb4.setIcon(Querys.img);
			ta1.setText("Modelo: "+ "" + Querys.Modelo + "" + "\n" + "Ano: " + "" + Querys.Ano + "");					
				}
			
			catch(Exception en){						
								}
										}
			if (e.getSource() == bt2) {
				
				Main m = new Main();
				m.setVisible(true);
				dispose();
				
			}
	
	}

}
